<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" >-->
<!--      <el-form-item label="国家" prop="country">-->
<!--        <el-input-->
<!--          v-model="queryParams.country"-->
<!--          placeholder="请输入国家"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:ranking:add']"-->
<!--        >新增排行</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['system:ranking:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->
    <div>{{title}}</div>
    <el-table border v-loading="loading" :data="rankingList"  v-show="showSearch">
      <el-table-column label="国家" align="center" prop="country" />
      <el-table-column label="金牌" align="center" prop="goldMedal" width="180">
        <template slot="header">
          <i class="icon_jin"></i>
          <span>金</span>
        </template>
      </el-table-column>
      <el-table-column label="银牌" align="center" prop="silverMedal" width="180">
        <template slot="header">
          <i class="icon_yin"></i>
          <span>银</span>
        </template>
      </el-table-column>
      <el-table-column label="铜牌" align="center" prop="bronze" width="180">
        <template slot="header">
          <i class="icon_tong"></i>
          <span>铜</span>
        </template>
      </el-table-column>
      <el-table-column label="总数" align="center" prop="sum" />
<!--      <el-table-column label="标签 " align="center" prop="tag" />-->
<!--      ：1-亚洲，2-非洲，3-欧洲，4-大洋洲，5-南美洲，6-北美洲，7-南极洲-->
<!--      <el-table-column label="最后修改时间-数据库默认写入时间" align="center" prop="updateTimeDb" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.updateTimeDb, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220px" >-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="small"-->
<!--            type="primary"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:ranking:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="small"-->
<!--            type="danger"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:ranking:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改排行榜对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="400px" append-to-body>-->
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="60px">-->
<!--        <el-form-item label="国家" prop="country" style="width:230px">-->
<!--          <el-input v-model="form.country" placeholder="请输入国家" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="金牌" prop="goldMedal" style="width:230px">-->
<!--          <el-input v-model="form.goldMedal" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" placeholder="请输入金牌数" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="银牌" prop="silverMedal" style="width:230px">-->
<!--          <el-input v-model="form.silverMedal" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" placeholder="请输入银牌数" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="铜牌" prop="bronze" style="width:230px">-->
<!--          <el-input v-model="form.bronze" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" placeholder="请输入铜牌数" />-->
<!--        </el-form-item>-->
<!--&lt;!&ndash;        <el-form-item label="总数" prop="sum">&ndash;&gt;-->
<!--&lt;!&ndash;          <el-input v-model="form.sum" placeholder="请输入总数" />&ndash;&gt;-->
<!--&lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
import { listRanking, getRanking, delRanking, addRanking, updateRanking } from "@/api/system/ranking";
import { getRankingsTable } from "@/api/system/table";

export default {
  name: "Ranking",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示table表格
      showSearch: true,
      // 总条数
      total: 0,
      // 排行榜表格数据
      rankingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        country: null,
        goldMedal: null,
        silverMedal: null,
        bronze: null,
        sum: null,
        tag: null,
        updateTimeDb: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        country: [
          { required: true, message: "国家不能为空", trigger: "blur" }
        ],
      },
      title:null
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询排行榜列表 */
    getList() {
      this.loading = true;
      getRankingsTable(this.queryParams).then(response => {
        this.rankingList = response.rows;
        if(this.rankingList.length == 0){
          this.showSearch = false
          this.title = '暂未有排名，请等待'
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        ranking: null,
        country: null,
        goldMedal: null,
        silverMedal: null,
        bronze: null,
        sum: null,
        tag: null,
        isDeleted: null,
        createUserid: null,
        createUsername: null,
        createTime: null,
        createTimeDb: null,
        serverIp: null,
        updateUserid: null,
        updateUsername: null,
        updateTime: null,
        updateTimeDb: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加排行榜";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRanking(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改排行榜";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRanking(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRanking(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除排行榜编号为"' + ids + '"的数据项？').then(function() {
        return delRanking(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/ranking/export', {
        ...this.queryParams
      }, `ranking_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.form {
  margin-top: 20px;
  margin-bottom: 10px;
}
.icon_jin {
  position: absolute;
  display: inline-block;
  left: 50px;
  padding-top: 1px;
  width: 20px;
  height: 29px;
  background-image: url(https://inews.gtimg.com/newsapp_bt/0/1231112549302_5173/0);
  background-position-x: initial;
  background-position-y: initial;
  background-size: 100%;
  background-repeat-x: initial;
  background-repeat-y: initial;
  background-attachment: initial;
  background-origin: initial;
  background-clip: initial;
  background-color: initial;
  background-size: 100%;
}
.icon_yin {
  position: absolute;
  display: inline-block;
  left: 50px;
  padding-top: 1px;
  width: 20px;
  height: 29px;
  background: url(https://inews.gtimg.com/newsapp_bt/0/1231113333499_5413/0) center no-repeat;
  background-image: url(https://inews.gtimg.com/newsapp_bt/0/1231113333499_5413/0);
  background-position-x: center;
  background-position-y: center;
  background-size: 100%;
  background-repeat-x: no-repeat;
  background-repeat-y: no-repeat;
  background-attachment: initial;
  background-origin: initial;
  background-clip: initial;
  background-color: initial;
  background-size: 100%;
}
.icon_tong {
  position: absolute;
  display: inline-block;
  left: 50px;
  padding-top: 1px;
  width: 20px;
  height: 29px;
  background: url(https://inews.gtimg.com/newsapp_bt/0/1231113331290_3204/0) center no-repeat;
  background-image: url(https://inews.gtimg.com/newsapp_bt/0/1231113331290_3204/0);
  background-position-x: center;
  background-position-y: center;
  background-size: 100%;
  background-repeat-x: no-repeat;
  background-repeat-y: no-repeat;
  background-attachment: initial;
  background-origin: initial;
  background-clip: initial;
  background-color: initial;
  background-size: 100%;
}
</style>
